import java.util.concurrent.Semaphore;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-08-17
 * Time: 16:31
 * To BE A Better Person-2020-3-2
 */

public class TestDemo {

    public static int a=0;
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore=new Semaphore(4);

        Runnable runnable=new Runnable() {
            @Override

            public void run() {
                try {

                    semaphore.acquire();
                    a++;
                    semaphore.release();

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        Thread t1=new Thread(runnable);
        Thread t2=new Thread(runnable);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(a);
    }
}
